<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 600px;
            margin: 100px auto;
        }
        .msg{
            display: inline-block;
            font-size: 12px;
            color: #999;
            background: url(images/mess.png) no-repeat left center;
            padding-left: 20px;
        }
        .wrong{
            color: red;
            background: url(images/wrong.png)

        }
        .right{
            color: green;
            background: url(images/right.png)
        }
    </style>
</head>
<body>
    <div>
        <input type="password" class="input">
        <p class="msg">请输入6~16位密码</p>
    </div>
    <script>
        var input=document.querySelector('.input');
        var msg=document.querySelector('.msg');
        input.onblur=function(){
            if(this.value.length<6 || this.value.length>16){
                console.log('错误');
                msg.className='msg wrong';
                msg.innerHTML='您输入的密码位数有误,密码要求6~16位'
            }else{
                msg.className='msg right';
                msg.innerHTML='您输入的正确';
            }
        }
    </script>
</body>
</html>